const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const path = require('path');

const app = express();

// 静态文件服务
app.use(express.static(path.join(__dirname, 'dist')));

// API 代理配置
const apiProxy = createProxyMiddleware({
  target: 'http://8.130.133.165:8800',
  changeOrigin: true,
  logLevel: 'debug'
});

// 代理所有 API 请求
app.use('/scholarship', apiProxy);
app.use('/user', apiProxy);
app.use('/grade', apiProxy);
app.use('/competitionCatalog', apiProxy);
app.use('/competitionParticipation', apiProxy);
app.use('/intellectualProperty', apiProxy);
app.use('/ipScoringRule', apiProxy);
app.use('/paperScoringRule', apiProxy);
app.use('/socialService', apiProxy);
app.use('/socialServiceRule', apiProxy);
app.use('/researchPaper', apiProxy);
app.use('/political', apiProxy);

// 处理 SPA 路由
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});

const PORT = 9000;
app.listen(PORT, () => {
  console.log(`Proxy server running on http://localhost:${PORT}`);
  console.log(`Proxying API requests to http://8.130.133.165:8800`);
}); 